package cn.iocoder.yudao.module.erp.controller.admin.gi.giwlmq;

import cn.iocoder.yudao.module.erp.dal.dataobject.giitem.GiItemWlmqDO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.erp.controller.admin.gi.giwlmq.vo.*;
import cn.iocoder.yudao.module.erp.dal.dataobject.gi.GiWlmqDO;
import cn.iocoder.yudao.module.erp.service.gi.GiWlmqService;

@Tag(name = "管理后台 - ERP物流乌鲁木齐仓库")
@RestController
@RequestMapping("/erp/gi-wlmq")
@Validated
public class GiWlmqController {

    @Resource
    private GiWlmqService giWlmqService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP物流乌鲁木齐仓库")
//    @PreAuthorize("@ss.hasPermission('erp:gi-wlmq:create')")
    public CommonResult<String> createGiWlmq(@Valid @RequestBody GiWlmqSaveReqVO createReqVO) {
        return success(giWlmqService.createGiWlmq(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP物流乌鲁木齐仓库")
//    @PreAuthorize("@ss.hasPermission('erp:gi-wlmq:update')")
    public CommonResult<Boolean> updateGiWlmq(@Valid @RequestBody GiWlmqSaveReqVO updateReqVO) {
        giWlmqService.updateGiWlmq(updateReqVO);
        return success(true);
    }

    @PutMapping("/examine")
    @Operation(summary = "ERP物流乌鲁木齐仓库单据审核")
//    @PreAuthorize("@ss.hasPermission('erp:gi-wlmq:examine')")
    public CommonResult<Boolean> examineGiWlmq(@Valid @RequestBody GiWlmqDO giWlmqDO) {
        giWlmqService.examineGiWlmq(giWlmqDO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP物流乌鲁木齐仓库")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('erp:gi-wlmq:delete')")
    public CommonResult<Boolean> deleteGiWlmq(@RequestParam("id") String id) {
        giWlmqService.deleteGiWlmq(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP物流乌鲁木齐仓库")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('erp:gi-wlmq:query')")
    public CommonResult<GiWlmqRespVO> getGiWlmq(@RequestParam("id") String id) {
        GiWlmqDO giWlmq = giWlmqService.getGiWlmq(id);
        return success(BeanUtils.toBean(giWlmq, GiWlmqRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP物流乌鲁木齐仓库分页")
//    @PreAuthorize("@ss.hasPermission('erp:gi-wlmq:query')")
    public CommonResult<PageResult<GiWlmqRespVO>> getGiWlmqPage(@Valid GiWlmqPageReqVO pageReqVO) {
        PageResult<GiWlmqDO> pageResult = giWlmqService.getGiWlmqPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GiWlmqRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP物流乌鲁木齐仓库 Excel")
//    @PreAuthorize("@ss.hasPermission('erp:gi-wlmq:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportGiWlmqExcel(@Valid GiWlmqPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<GiWlmqDO> list = giWlmqService.getGiWlmqPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP物流乌鲁木齐仓库.xls", "数据", GiWlmqRespVO.class,
                        BeanUtils.toBean(list, GiWlmqRespVO.class));
    }

    @GetMapping("/gi-item-wlmq/list-by-no")
    @Operation(summary = "获得ERP物流乌鲁木齐仓库货号详情列表")
    @Parameter(name = "no", description = "入库编号")
//    @PreAuthorize("@ss.hasPermission('erp:gi-wlmq:detail')")
    public CommonResult<List<GiItemWlmqDO>> getGiItemWlmqListByNo(@RequestParam("no") String no) {
        return success(giWlmqService.getGiItemWlmqListByNo(no));
    }

}